<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

$user_id = $user->getUserId();
$user_ip = $_SERVER['REMOTE_ADDR'];

// проверяем - не голосовал ли уже пользователь
$query = $user_id ? "select count(`vote_id`) from `votes` where `user_id` = '$user_id' or `user_ip` = '$user_ip'" : "select count(`vote_id`) from `votes` where `user_ip` = '$user_ip'";
$vote = $db->getCell($query);

if ($vote != "0")
	die("vote");

$choice = UV::readMQ(strip_tags($route->POST("choice")));

switch($choice)
{
	case "ER":		$candidate_id = 1; break;
	case "KPRF":	$candidate_id = 2; break;
	case "SP":		$candidate_id = 3; break;
	case "LDPR":	$candidate_id = 4; break;
	case "PR":		$candidate_id = 5; break;
	case "YA":		$candidate_id = 6; break;
	case "PD":		$candidate_id = 7; break;
	case "AA":		$candidate_id = 8; break;
	default: die("candidate");
}

$db->sendQuery("insert into `votes` values (NULL,'$user_id','$user_ip','$candidate_id')");

?>